var fs = require('fs');
var path = require('path')
var folder = process.argv[2];
console.log('folder',folder)
function parseFile(fileName, exportPath) {
	console.log("parseFile  fileName ", fileName)
	let data = fs.readFileSync(fileName)
	fileName = fileName.replace(/-removebg-preview/,'')
	console.log(" fileName ",fileName)
	fs.writeFileSync(fileName,data);

}

function readDir(dir, exportPath) {

	// console.log(' readDir ===================')
	var stat = fs.statSync(dir);
	if (!stat.isDirectory()) {
		return;
	}
	var subpaths = fs.readdirSync(dir),
		subpath;
	for (var i = 0; i < subpaths.length; ++i) {
		if (subpaths[i][0] === '.') {
			continue;
		}
		subpath = path.join(dir, subpaths[i]);
		// console.log(' readDir   subpath ', subpath)
		stat = fs.statSync(subpath);
		if (stat.isDirectory()) {
			readDir(subpath, exportPath);
		} else if (stat.isFile()) {
			parseFile(subpath, exportPath);
		}
	}
}

readDir(folder,folder);